home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Tools / mpp88 / mpp88.py < prev    next >
Encoding:
Text File  |  1991-12-18  |  5.6 KB  |  273 lines

  1. -- mpp88.py: - test out PEPY
  2.  
  3.  
  4. -- @(#) $Header: /xtel/pp/pp-beta/Tools/mpp88/RCS/mpp88.py,v 6.0 1991/12/18 20:31:43 jpo Rel $
  5. --
  6. -- $Log: mpp88.py,v $
  7. -- Revision 6.0  1991/12/18  20:31:43  jpo
  8. -- Release 6.0
  9. --
  10. --
  11. --
  12.  
  13.  
  14. MPP DEFINITIONS   ::=
  15.  
  16. %{
  17. #ifndef lint
  18. static char *rcsid = "$Header: /xtel/pp/pp-beta/Tools/mpp88/RCS/mpp88.py,v 6.0 1991/12/18 20:31:43 jpo Rel $";
  19. #endif  lint
  20.  
  21. #include <stdio.h>
  22. #include "Trans-types.h"
  23. #include "IOB-types.h"
  24.  
  25.  
  26. #define ps_advise(ps, f) \
  27.         advise (NULLCP, "%s: %s", (f), ps_error ((ps) -> ps_errno))
  28.  
  29. /*     DATA */
  30. int        unpack = 1;
  31. static char    *myname = "mpp88";
  32. static enum    { ps2mpp, pl2mpp } mode = ps2mpp;
  33. static enum    format { p1, p2, p2hdr, ipn} topfmt = p2;
  34. void        adios ();
  35.  
  36.  
  37. /*     MAIN */
  38.  
  39. /* ARGSUSED */
  40.  
  41. main (argc, argv, envp)
  42. int     argc;
  43. char  **argv,
  44.       **envp;
  45. {
  46.     register int    status = 0;
  47.     register char  *cp;
  48.     register FILE  *fp;
  49.  
  50.     if (myname = rindex (argv[0], '/'))
  51.         myname++;
  52.     if (myname == NULL || *myname == NULL)
  53.         myname = argv[0];
  54.  
  55.     for (argc--, argv++; cp = *argv; argc--, argv++)
  56.         if (*cp == '-') {
  57.             if (strcmp (cp + 1, "ps") == 0) {
  58.                 mode = ps2mpp;
  59.                 continue;
  60.             }
  61.             if (strcmp (cp + 1, "pl") == 0) {
  62.                 mode = pl2mpp;
  63.                 continue;
  64.             }
  65.             if (strcmp (cp + 1, "p1") == 0) {
  66.                 topfmt = p1;
  67.                 continue;
  68.             }
  69.             if (strcmp (cp + 1, "p2") == 0) {
  70.                 topfmt = p2;
  71.                 continue;
  72.             }
  73.         if (strcmp (cp + 1, "nounpack") == 0) {
  74.         unpack = 0;
  75.         continue;
  76.         }
  77.         if (strcmp (cp + 1, "p2hdr") == 0) {
  78.         topfmt = p2hdr;
  79.         continue;
  80.         }
  81.         if (strcmp (cp + 1, "ipn") == 0) {
  82.         topfmt = ipn;
  83.         continue;
  84.         }
  85.             adios (NULLCP, "usage: %s [ -ps | -pe ] [-p1 | -p2 | -p2hdr | -ipn ] [ files... ]",
  86.                     myname);
  87.         }
  88.         else
  89.             break;
  90.  
  91.     if (argc == 0)
  92.         status = process ("(stdin)", stdin);
  93.     else
  94.         while (cp = *argv++) {
  95.             if ((fp = fopen (cp, "r")) == NULL) {
  96.                 advise (cp, "unable to read");
  97.                 status++;
  98.                 continue;
  99.             }
  100.             status += process (cp, fp);
  101.             (void) fclose (fp);
  102.         }
  103.  
  104.     exit (status);              /* NOTREACHED */
  105. }
  106.  
  107. /*   */
  108.  
  109. static int  process (file, fp)
  110. register char *file;
  111. register FILE *fp;
  112. {
  113.     enum format curfmt = topfmt;
  114.     register PE     pe;
  115.     register PS     ps;
  116.  
  117.     if ((ps = ps_alloc (std_open)) == NULLPS) {
  118.         ps_advise (ps, "ps_alloc");
  119.         return 1;
  120.     }
  121.     if (std_setup (ps, fp) == NOTOK) {
  122.         advise (NULLCP, "%s: std_setup loses", file);
  123.         return 1;
  124.     }
  125.  
  126.     for (;;) {
  127.         switch (mode) {
  128.             case ps2mpp: 
  129.                 if ((pe = ps2pe (ps)) == NULLPE)
  130.                     if (ps -> ps_errno) {
  131.                         ps_advise (ps, "ps2pe");
  132.                 you_lose: ;
  133.             if (pe != NULLPE)
  134.                 pe_free (pe);
  135.             ps_free (ps);
  136.                         return 1;
  137.                     }
  138.                     else {
  139.                 done:   ;
  140.                         ps_free (ps);
  141.                         return 0;
  142.                     }
  143.                 break;
  144.  
  145.             case pl2mpp: 
  146.                 if ((pe = pl2pe (ps)) == NULLPE)
  147.                     if (ps -> ps_errno) {
  148.                         ps_advise (ps, "pl2pe");
  149.                         goto you_lose;
  150.                     }
  151.                     else
  152.                         goto done;
  153.                 break;
  154.         }
  155.  
  156.         switch (curfmt) {
  157.             case p1:
  158.             default:
  159.         (void) print_Trans_MtsAPDU (pe, 1, 0, NULLCP, NULL);
  160.                 break;
  161.  
  162.             case p2:
  163.                 (void) print_IOB_InformationObject (pe, 1, NULLIP, NULLVP, NULLCP);
  164.                 break;
  165.         case p2hdr:
  166.         (void) print_IOB_Heading (pe, 1, NULLIP, NULLVP, NULLCP);
  167.         break;
  168.         case ipn:
  169.         (void) print_IOB_IPN (pe, 1, NULLIP, NULLVP, NULLCP);
  170.         break;
  171.         }
  172.  
  173.         pe_free (pe);
  174.     }
  175. }
  176.  
  177. /*   */
  178.  
  179. %}
  180.  
  181. BEGIN
  182.  
  183. END
  184.  
  185. %{
  186. /*     DEBUG */
  187.  
  188. #ifdef  DEBUG
  189. testdebug (pe, s)
  190. register PE pe;
  191. register char *s;
  192. {
  193.     static int  debug = OK;
  194.     char   *cp;
  195.     register PS     ps;
  196.  
  197.     switch (debug) {
  198.         case NOTOK: 
  199.             break;
  200.  
  201.         case OK: 
  202.             if ((debug = (cp = getenv ("PEPYDEBUG")) && *cp ? atoi (cp)
  203.                         : NOTOK) == NOTOK)
  204.                 break;
  205.             fprintf (stderr, "%s made with %s\n", myname, pepyid);
  206.  
  207.         default: 
  208.             fprintf (stderr, "%s\n", s);
  209.  
  210.             if ((ps = ps_alloc (std_open)) == NULLPS)
  211.                 return;
  212.             if (std_setup (ps, stderr) != NOTOK)
  213.                 (void) pe2pl (ps, pe);
  214.             fprintf (stderr, "--------\n");
  215.             ps_free (ps);
  216.             break;
  217.     }
  218. }
  219. #endif  DEBUG
  220.  
  221. /*     ERRORS */
  222.  
  223. /* VARARGS2 */
  224.  
  225. void    adios (what, fmt, a, b, c, d, e, f, g, h, i, j)
  226. char   *what,
  227.        *fmt,
  228.        *a,
  229.        *b,
  230.        *c,
  231.        *d,
  232.        *e,
  233.        *f,
  234.        *g,
  235.        *h,
  236.        *i,
  237.        *j;
  238. {
  239.     advise (what, fmt, a, b, c, d, e, f, g, h, i, j);
  240.     _exit (1);
  241. }
  242.  
  243. /*   */
  244.  
  245. /* VARARGS2 */
  246.  
  247. void    advise (what, fmt, a, b, c, d, e, f, g, h, i, j)
  248. char   *what,
  249.        *fmt,
  250.        *a,
  251.        *b,
  252.        *c,
  253.        *d,
  254.        *e,
  255.        *f,
  256.        *g,
  257.        *h,
  258.        *i,
  259.        *j;
  260. {
  261.     (void) fflush (stdout);
  262.  
  263.     fprintf (stderr, "%s: ", myname);
  264.     fprintf (stderr, fmt, a, b, c, d, e, f, g, h, i, j);
  265.     if (what)
  266.         (void) fputc (' ', stderr), perror (what);
  267.     else
  268.         (void) fputc ('\n', stderr);
  269.     (void) fflush (stderr);
  270. }
  271.  
  272. %}
  273.